<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="88px">
			<el-form-item label="进出状态" prop="type">
				<el-select v-model="queryParams.type" placeholder="请选择进出状态" clearable>
					<el-option v-for="dict in in_out_door" :key="dict.value" :label="dict.label" :value="dict.value" />
				</el-select>
			</el-form-item>
			<el-form-item label="记录时间" style="width: 308px;">
				<el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
				 start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
				<el-button icon="Refresh" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['archive:ArchiveBoxInoutRecords:export']">导出</el-button>
			</el-col>
			<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="ArchiveBoxInoutRecordsList" @selection-change="handleSelectionChange">
			<el-table-column label="序号" align='center' width="100">
				<template #default="scope">
					{{ scope.$index+1 }}
				</template>
			</el-table-column>
			<el-table-column label="档案室编号" align="center" prop="roomNo" />
			<el-table-column label="记录时间" align="center" prop="recTime" width="180">
				<template #default="scope">
					<span>{{ parseTime(scope.row.recTime) }}</span>
				</template>
			</el-table-column>
			<!--      <el-table-column label="1进档案室  2出档案室" align="center" prop="type" />-->
			<el-table-column label="进出状态" align="center" prop="type">
				<template #default="scope">
					<dict-tag :options="in_out_door" :value="scope.row.type" />
				</template>
			</el-table-column>
			<!--      <el-table-column label="推送状态01 已推送 02 未推送" align="center" prop="pushStatus" />-->
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<!--        <template #default="scope">-->
				<!--          <el-button-->
				<!--            type="text"-->
				<!--            icon="Edit"-->
				<!--            @click="handleUpdate(scope.row)"-->
				<!--            v-hasPermi="['archive:ArchiveBoxInoutRecords:edit']"-->
				<!--          >修改</el-button>-->
				<!--          <el-button-->
				<!--            type="text"-->
				<!--            icon="Delete"-->
				<!--            @click="handleDelete(scope.row)"-->
				<!--            v-hasPermi="['archive:ArchiveBoxInoutRecords:remove']"-->
				<!--          >删除</el-button>-->
				<!--        </template>-->
				<template #default="scope">
					<el-button type="text" icon="View" @click="handleView(scope.row, scope.index)" v-hasPermi="['archive:ArchiveBoxInoutRecords:query']">详细</el-button>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
		 @pagination="getList" />

		<!-- 添加或修改档案盒盒记录上报对话框 -->
		<!--    <el-dialog :title="title" v-model="open" width="500px" append-to-body>-->
		<!--      <el-form ref="ArchiveBoxInoutRecordsRef" :model="form" :rules="rules" label-width="120px">-->
		<!--        <el-form-item label="记录序号" prop="id">-->
		<!--          <el-input v-model="form.id" placeholder="请输入记录序号" />-->
		<!--        </el-form-item>-->
		<!--        <el-form-item label="接口编号" prop="interfaceNo">-->
		<!--          <el-input v-model="form.interfaceNo" placeholder="请输入接口编号" />-->
		<!--        </el-form-item>-->
		<!--        <el-form-item label="渠道编号" prop="channelNo">-->
		<!--          <el-input v-model="form.channelNo" placeholder="请输入渠道编号" />-->
		<!--        </el-form-item>-->
		<!--        <el-form-item label="供电单位编号" prop="orgNo">-->
		<!--          <el-input v-model="form.orgNo" placeholder="请输入供电单位编号" />-->
		<!--        </el-form-item>-->
		<!--        <el-form-item label="档案室编号" prop="roomNo">-->
		<!--          <el-input v-model="form.roomNo" placeholder="请输入档案室编号" />-->
		<!--        </el-form-item>-->
		<!--        <el-form-item label="记录时间" prop="recTime">-->
		<!--          <el-date-picker clearable-->
		<!--            v-model="form.recTime"-->
		<!--            type="datetime"-->
		<!--            value-format="yyyy-MM-dd HH:mm:ss"-->
		<!--            placeholder="请选择记录时间">-->
		<!--          </el-date-picker>-->
		<!--          <el-date-picker clearable-->
		<!--                  v-model="form.recTime"-->
		<!--                  type="datetime"-->
		<!--                  value-format="yyyy-MM-dd HH:mm:ss"-->
		<!--                   placeholder="请选择记录时间">-->
		<!--            </el-date-picker>-->
		<!--          <el-input v-model="form.recTime" placeholder="请输入记录时间" />-->
		<!--        </el-form-item>-->
		<!--      </el-form>-->
		<!--      <template #footer>-->
		<!--        <div class="dialog-footer">-->
		<!--          <el-button type="primary" @click="submitForm">确 定</el-button>-->
		<!--          <el-button @click="cancel">取 消</el-button>-->
		<!--        </div>-->
		<!--      </template>-->
		<!--    </el-dialog>-->

		<!-- 查看详细 -->
		<el-dialog title="档案盒进出记录详细" v-model="openscan" width="80%" append-to-body>
			<el-form ref="ArchiveBoxInoutRecordsRef" :model="form" label-width="130px">
				<el-row>
					<el-col :span="6">
						<el-form-item label="供电单位编号：">
							<el-input v-model="form.orgNo" disabled="disabled" />
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="档案室编号：">
							<el-input v-model="form.roomNo" disabled="disabled" />
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="进出状态：">
							<template #default="scope">
								<dict-tag :options="in_out_door" :value="form.type" />
							</template>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="记录时间：">
							<el-input v-model="form.recTime" disabled="disabled" />
						</el-form-item>
					</el-col>
				</el-row>
				<!--        <el-divider content-position="center">档案盒记录详细数据</el-divider>-->
				<el-table :data="archiveBoxList" style="min-height: 550px;border:1px solid #dcdfe6;max-height: 550px;"
				 :highlight-current-row="true" height="550" border>
					<el-table-column label="序号" align='center'>
						<template #default="scope">
							{{ scope.$index+1 }}
						</template>
					</el-table-column>
					<el-table-column label="档案盒号" prop="boxNo" align="center" />
					<el-table-column label="档案区编号" align="center" prop="areaNo" />
					<el-table-column label="档案柜编号" align="center" prop="cabinetNo" />
					<el-table-column label="档案盒条码" prop="boxRfid" align="center" />
					<el-table-column label="库位号" prop="houseLocationNo" align="center">
					</el-table-column>
				</el-table>
			</el-form>
			<template #footer>
				<div class="dialog-footer">
					<el-button @click="openscan = false">关 闭</el-button>
				</div>
			</template>
		</el-dialog>
	</div>
</template>

<script setup name="ArchiveBoxInoutRecords">
	import {
		listArchiveBoxInoutRecords,
		getArchiveBoxInoutRecords,
		delArchiveBoxInoutRecords,
		addArchiveBoxInoutRecords,
		updateArchiveBoxInoutRecords,
		getBoxInoutRecordList
	} from "@/api/archive/ArchiveBoxInoutRecords";
	import {
		getCurrentInstance,
		reactive,
		ref,
		toRefs
	} from "vue";

	const {
		proxy
	} = getCurrentInstance();

	const ArchiveBoxInoutRecordsList = ref([]);
	const open = ref(false);
	const loading = ref(true);
	const showSearch = ref(true);
	const ids = ref([]);
	const single = ref(true);
	const multiple = ref(true);
	const total = ref(0);
	const title = ref("");
	const archiveBoxList = ref([]);
	const data = reactive({
		form: {},
		queryParams: {
			pageNum: 1,
			pageSize: 10,
			interfaceNo: null,
			channelNo: null,
			orgNo: null,
			roomNo: null,
			recTime: null,
			type: null,
			pushStatus: null
		},
		rules: {
			// id: [
			//   { required: true, message: "记录序号不能为空", trigger: "blur" }
			// ],
		}
	});

	const {
		queryParams,
		form,
		rules
	} = toRefs(data);
	const dateRange = ref([]);
	const {
		push_status,
		in_out_door
	} = proxy.useDict('push_status', 'in_out_door');
	const openscan = ref(false);
	/** 查询档案盒盒记录上报列表 */
	function getList() {
		loading.value = true;
		listArchiveBoxInoutRecords(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
			//listArchiveBoxInoutRecords(queryParams.value).then(response => {
			ArchiveBoxInoutRecordsList.value = response.rows;
			total.value = response.total;
			loading.value = false;
		});
	}

	// 取消按钮
	function cancel() {
		open.value = false;
		reset();
	}

	// 表单重置
	function reset() {
		form.value = {
			id: null,
			interfaceNo: null,
			channelNo: null,
			orgNo: null,
			roomNo: null,
			recTime: null,
			type: null,
			pushStatus: "0"
		};
		proxy.resetForm("ArchiveBoxInoutRecordsRef");
	}

	/** 搜索按钮操作 */
	function handleQuery() {
		queryParams.value.pageNum = 1;
		getList();
	}

	/** 重置按钮操作 */
	function resetQuery() {
		dateRange.value = [];
		proxy.resetForm("queryRef");
		handleQuery();
	}

	// 多选框选中数据
	function handleSelectionChange(selection) {
		ids.value = selection.map(item => item.id);
		single.value = selection.length != 1;
		multiple.value = !selection.length;
	}

	/** 新增按钮操作 */
	function handleAdd() {
		reset();
		open.value = true;
		title.value = "添加档案盒记录";
	}

	/** 修改按钮操作 */
	function handleUpdate(row) {
		reset();
		const id = row.id || ids.value
		getArchiveBoxInoutRecords(id).then(response => {
			form.value = response.data;
			open.value = true;
			title.value = "修改档案盒记录";
		});
	}

	/** 提交按钮 */
	function submitForm() {
		proxy.$refs["ArchiveBoxInoutRecordsRef"].validate(valid => {
			if (valid) {
				if (form.value.id != null) {
					updateArchiveBoxInoutRecords(form.value).then(response => {
						proxy.$modal.msgSuccess("修改成功");
						open.value = false;
						getList();
					});
				} else {
					addArchiveBoxInoutRecords(form.value).then(response => {
						proxy.$modal.msgSuccess("新增成功");
						open.value = false;
						getList();
					});
				}
			}
		});
	}

	/** 删除按钮操作 */
	function handleDelete(row) {
		const delid = row.id || ids.value
		proxy.$modal.confirm('是否确认删除档案盒盒记录上报编号为"' + id + '"的数据项？').then(function() {
			return delArchiveBoxInoutRecords(delid);
		}).then(() => {
			getList();
			proxy.$modal.msgSuccess("删除成功");
		}).catch(() => {});
	}

	/** 导出按钮操作 */
	function handleExport() {
		proxy.download('archive/ArchiveBoxInoutRecords/export', {
			...queryParams.value
		}, `档案盒记录_${new Date().getTime()}.xlsx`)
	}

	function handleView(row) {
		openscan.value = true;
		form.value = row;
		getBoxInoutRecordList(row.id).then(response => {
			if (response.code == "200") {
				archiveBoxList.value = response.data;
			} else {
				proxy.$modal.msgError(response.msg);
			}
		});
	}
	getList();
</script>
